home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <sys/types.h>
- #include <sys/uio.h>
- #include "NDR.h"
-
- extern "C" {
- unsigned short htons(unsigned short);
- };
-
-
- RJS_Transport &operator<<(RJS_Transport &tr, RJS_NDR_send &ndr)
- {
- unsigned short len=htons(ndr.raw_length());
- struct iovec iov[2];
- iov[0].iov_base = (char *) &len;
- iov[0].iov_len = sizeof(unsigned short);
- iov[1].iov_base = ndr.raw_data();
- iov[1].iov_len = ndr.raw_length();
- tr.writev(iov,2);
- return tr;
- }
-
- ostream &operator<<(ostream &os, RJS_NDR_send &ndr)
- {
- cout << "local_endian() => " << ndr.local_endian() << endl;
- cout << "local_character() => " << ndr.local_character() << endl;
- cout << "local_floating() => " << ndr.local_floating() << endl;
- cout << "raw_length() => " << ndr.raw_length() << endl;
- for (int i=0; i< ndr.raw_length(); i++) {
- cout << i << "\t" << int(*(ndr.raw_data()+i)) << endl;
- }
- return os;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr, RJS_XNDR &x) {
- x.to_external(ndr);
- return ndr;
- }
-
- RJS_NDR_send::RJS_NDR_send()
- {
- start_data=NULL;
- end_data=NULL;
- end_alloc=NULL;
- }
-
-
- void RJS_NDR_send::reset()
- {
- end_data = start_data+2;
- }
-
- void RJS_NDR_send::init(char *buffer, int size)
- {
- int align=((unsigned int)(buffer)) % sizeof(double);
- if (align) buffer += (sizeof(double)-align);
- start_data = buffer;
- end_data = buffer;
- end_alloc = buffer+size;
- (*end_data++) = (local_endian() << 4) | (local_character());
- (*end_data++) = (local_floating());
-
- }
-
- RJS_NDR_send &RJS_NDR_send::insert(char *d, int count)
- {
- (*this) << count;
- strncpy(end_data,d,count);
- end_data += count;
- return *this;
- }
-
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,char ch)
- {
- *ndr.end_data++ = ch;
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,unsigned char ch)
- {
- *ndr.end_data++ = ch;
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,short i)
- {
- if (((unsigned int)(ndr.end_data)) % sizeof(short)) ndr.end_data++;
- * (short *) ndr.end_data = i;
- ndr.end_data += sizeof(short);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,unsigned short i)
- {
- if (((unsigned int)(ndr.end_data)) % sizeof(unsigned short)) ndr.end_data++;
- * (unsigned short *) ndr.end_data = i;
- ndr.end_data += sizeof(unsigned short);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,int i)
- {
- int align=((unsigned int)(ndr.end_data)) % sizeof(int);
- if (align) ndr.end_data += (sizeof(int)-align); // align on natural
- * (int *) ndr.end_data = i;
- ndr.end_data += sizeof(int);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,unsigned int i)
- {
- int align=((unsigned int)(ndr.end_data)) % sizeof(unsigned int);
- if (align) ndr.end_data += (sizeof(unsigned int)-align);
- * (unsigned int *) ndr.end_data = i;
- ndr.end_data += sizeof(unsigned int);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,float d)
- {
- int align=((unsigned int)(ndr.end_data)) % sizeof(float);
- if (align) ndr.end_data += (sizeof(float)-align);
- * (float *) ndr.end_data = d;
- ndr.end_data += sizeof(float);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,double d)
- {
- int align=((unsigned int)(ndr.end_data)) % sizeof(double);
- if (align) ndr.end_data += (sizeof(double)-align);
- * (double *) ndr.end_data = d;
- ndr.end_data += sizeof(double);
- return ndr;
- }
-
- RJS_NDR_send &operator<<(RJS_NDR_send &ndr,const char *str)
- {
- unsigned short len=strlen(str)+1;
- ndr << len;
- strcpy(ndr.end_data,str);
- ndr.end_data += len;
- return ndr;
- }
-
-
-